/* 8911106 302933981 Ofri Keidar */

/******************************************************************************
* Student Name: Ofri Keidar
* Exercise Name: Ex6
* File Description: Class Sale's implementation
******************************************************************************/


#include "Sale.h"

/***************************************************************************************
* function name: Sale(const int amount = DEFLT_AMOUNT, const Item* itemSold = NULL)
* The Input: Ordered amount and pointer to item to be sold
* The output: None
* The Function operation: Creates a new sale for given item
***************************************************************************************/
Sale::Sale(const int amount, const Item* itemSold) {
	m_amoutToSale = amount; // set amount to sale as given amount
	m_itemSold = itemSold; // set item pointer at given item
	m_balanceStockOrder = NULL; // no ordered as been made yet
}

/***************************************************************************************
* function name: Sale(const Sale& saleToCopy)
* The Input: Sale object to be copied
* The output: None
* The Function operation: Creates a new sale with the same attributes of given sale
***************************************************************************************/
Sale::Sale(const Sale& saleToCopy): m_amoutToSale(saleToCopy.m_amoutToSale) {
	m_itemSold = saleToCopy.m_itemSold; // set new sale's item pointer to given sale's item
	m_balanceStockOrder = saleToCopy.m_balanceStockOrder; // set order attribute as given sale's
}

/***************************************************************************************
* function name: ~Sale()
* The Input: None
* The output: None
* The Function operation: Empty implementation since pointed order is deleted by order
* 					      tracker and pointed item is deleted by catalog
***************************************************************************************/
Sale::~Sale() {
	m_balanceStockOrder = NULL; // avoid deleting data
}

/***************************************************************************************
 * function name: friend ostream& operator << (ostream &os, const Sale& saleToPrint)
 * The Input: Reference to sale to be printed
 * The output: ostream reference
 * The Function operation: Prints sale's details
 ***************************************************************************************/
ostream& operator << (ostream &os, const Sale& saleToPrint) {
	cout << "Sale:["<< *(saleToPrint.m_itemSold) << "," << saleToPrint.m_amoutToSale << "]";
	// check if ordered is made within sale
	if (saleToPrint.m_balanceStockOrder != NULL) {
		cout << ",Order:" << *(saleToPrint.m_balanceStockOrder); // print sale's order
	}

	return os;
}
